﻿using JzSport.Model;
using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Threading.Tasks;

namespace JzSport.Api
{
    class SendMessageToActivityAction : AuthPostAction<Params.SendMessageToActivityParams,
        Results.SendMessageToActivityResult>
    {
        protected override ActionResult<Results.SendMessageToActivityResult> OnExecute(ActionContext context, SysParameters sysParameters,
            Params.SendMessageToActivityParams opParams)
        {
            ServiceResult<string> serviceResult = new MessageService().SendToActivity(context.AccountId,
                opParams.ActivityId,
                opParams.Content);

            Results.SendMessageToActivityResult actionResult = new Results.SendMessageToActivityResult();

            if (serviceResult.ErrorCode == ErrorCode.NoError)
            {
                return new ActionResult<Results.SendMessageToActivityResult>(true, serviceResult.ErrorCode,
                    ErrorCode.ToString(serviceResult.ErrorCode), actionResult);
            }
            return new ActionResult<Results.SendMessageToActivityResult>(false, serviceResult.ErrorCode,
                    ErrorCode.ToString(serviceResult.ErrorCode), actionResult);
        }
    }
}
